package ${package}.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neusoft.jn.common.base.BaseController;
import ${package}.entity.${TableName};
import ${package}.service.${TableName}Service;
import com.neusoft.jn.sys.common.annotation.Log;
import com.neusoft.jn.sys.common.core.domain.AjaxResult;
import com.neusoft.jn.sys.common.core.page.TableDataInfo;
import com.neusoft.jn.sys.common.enums.BusinessType;
import com.neusoft.jn.sys.common.utils.poi.ExcelUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.apache.commons.lang3.StringUtils;
import javax.annotation.Resource;
import java.util.List;

/**
* ${tableComment!}
* @author mengshx
* @since 2024-07-11
*/
@RestController
@RequestMapping("/${tableName}")
public class ${TableName}Controller extends BaseController {
    @Resource
    private ${TableName}Service service;

    /**
     * 新增保存
     */
    @Log(title = "${tableComment!}", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(${TableName} ${tableName})
    {
        return toAjax(service.save(${tableName}));
    }
    /**
     * 删除
     */
    @Log(title = "${tableComment!}", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(service.removeByIds(splitToList(ids)));
    }
    /**
     * 修改保存
     */
    @Log(title = "${tableComment!}", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(${TableName} ${tableName})
    {
        return toAjax(service.updateById(${tableName}));
    }
    /**
     * 查询列表
     **/
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(${TableName} ${tableName})
    {
        startPage();
        QueryWrapper queryWrapper = ${tableName}.genQryWrapper();
<#list  columns as field>
    <#if field.javaType=="String">
        if (StringUtils.isNotBlank(${tableName}.get${field.ColumnName!}())) {
        queryWrapper.eq("${field.COLUMN_NAME!}", ${tableName}.get${field.ColumnName!}());
        }
    </#if>
</#list>



        List<${TableName}> list = service.list(queryWrapper);
        return getDataTable(list);
    }


    /**
     * 导出列表
     */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(${TableName} ${tableName})
    {
        QueryWrapper queryWrapper = ${tableName}.genQryWrapper();
<#list  columns as field>
    <#if field.javaType=="String">
        if (StringUtils.isNotBlank(${tableName}.get${field.ColumnName!}())) {
        queryWrapper.like("${field.COLUMN_NAME!}", ${tableName}.get${field.ColumnName!}());
        }
    </#if>
</#list>
        List<${TableName}> list = service.list(queryWrapper);
        ExcelUtil<${TableName}> util = new ExcelUtil<${TableName}>(${TableName}.class);
        return util.exportExcel(list, "orgTreePlan");
    }
}

